home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Profi Tools / DiskSpeed / src / renderinfo.c < prev    next >
C/C++ Source or Header  |  1998-07-30  |  6KB  |  204 lines

  1. /*
  2.  * MKSoft Development Amiga ToolKit V1.0
  3.  *
  4.  * Copyright (c) 1985,86,87,88,89,90 by MKSoft Development
  5.  *
  6.  *                          DiskSpeed v4.2
  7.  *                          ScsiSpeed v4.2
  8.  *                                by
  9.  *                           Michael Sinz
  10.  *
  11.  *            Copyright (c) 1989-1992 by MKSoft Development
  12.  *
  13.  *            MKSoft Development
  14.  *            163 Appledore Drive
  15.  *            Downingtown, PA 19335
  16.  *
  17.  * Yes, this is yet another disk speed testing program, but with a few
  18.  * differences.  It was designed to give the most accurate results of the
  19.  * true disk performance in the system.  For this reason many of
  20.  * DiskSpeed's results may look either lower or higher than current disk
  21.  * performance tests.
  22.  *
  23.  ******************************************************************************
  24.  *                                          *
  25.  *    Reading legal mush can turn your brain into guacamole!              *
  26.  *                                          *
  27.  *        So here is some of that legal mush:                  *
  28.  *                                          *
  29.  * Permission is hereby granted to distribute this program's source          *
  30.  * executable, and documentation for non-commercial purposes, so long as the  *
  31.  * copyright notices are not removed from the sources, executable or          *
  32.  * documentation.  This program may not be distributed for a profit without   *
  33.  * the express written consent of the author Michael Sinz.              *
  34.  *                                          *
  35.  * This program is not in the public domain.                      *
  36.  *                                          *
  37.  * Fred Fish is expressly granted permission to distribute this program's     *
  38.  * source and executable as part of the "Fred Fish freely redistributable     *
  39.  * Amiga software library."                              *
  40.  *                                          *
  41.  * Permission is expressly granted for this program and it's source to be     *
  42.  * distributed as part of the Amicus Amiga software disks, and the          *
  43.  * First Amiga User Group's Hot Mix disks.                      *
  44.  *                                          *
  45.  ******************************************************************************
  46.  */
  47.  
  48. /*
  49.  * This file contains the definition of the rendering information
  50.  * for elements on the screen.  This information is used to generate
  51.  * the correct pen colours for items on the screen...
  52.  */
  53.  
  54. #include    <exec/types.h>
  55. #include    <exec/memory.h>
  56. #include    <graphics/view.h>
  57. #include    <graphics/text.h>
  58. #include    <intuition/intuition.h>
  59. #include    <intuition/screens.h>
  60.  
  61. #include    <proto/exec.h>
  62. #include    <proto/intuition.h>
  63. #include    <proto/graphics.h>
  64.  
  65. #include    "RenderInfo.h"
  66.  
  67. /*
  68.  * These define the amount of Red, Green, and Blue scaling used
  69.  * to help take into account the different visual impact of those
  70.  * colours on the screen.
  71.  */
  72. #define    BLUE_SCALE    2
  73. #define    GREEN_SCALE    6
  74. #define    RED_SCALE    3
  75.  
  76. #define    MAX_COLOURS    16
  77.  
  78. /*
  79.  * This returns the colour difference hamming value...
  80.  */
  81. SHORT ColourDifference(UWORD rgb0, UWORD rgb1)
  82. {
  83. register    SHORT    level;
  84. register    SHORT    tmp;
  85.  
  86.     tmp=(rgb0 & 15) - (rgb1 & 15);
  87.     level=tmp*tmp*BLUE_SCALE;
  88.     tmp=((rgb0>>4) & 15) - ((rgb1>>4) & 15);
  89.     level+=tmp*tmp*GREEN_SCALE;
  90.     tmp=((rgb0>>8) & 15) - ((rgb1>>8) & 15);
  91.     level+=tmp*tmp*RED_SCALE;
  92.     return(level);
  93. }
  94.  
  95. /*
  96.  * Calculate a rough brightness hamming value...
  97.  */
  98. #define    ColourLevel(x)    ColourDifference(x,0)
  99.  
  100. /*
  101.  * For new programs, this also opens fonts...
  102.  */
  103. static VOID NewFillIn_RenderInfo(struct RenderInfo *ri,struct Screen *TheScreen)
  104. {
  105. register    SHORT        numcolours;
  106. register    SHORT        loop;
  107. register    SHORT        loop1;
  108. register    SHORT        backpen;
  109. register    SHORT        tmp;
  110.         SHORT        colours[MAX_COLOURS];
  111.         SHORT        colourlevels[MAX_COLOURS];
  112.         SHORT        pens[MAX_COLOURS];
  113.     struct    Screen        screen;
  114.  
  115.     if (!TheScreen) GetScreenData((APTR)(TheScreen=&screen),sizeof(struct Screen),WBENCHSCREEN,NULL);
  116.  
  117.     ri->WindowTitle=TheScreen->BarHeight-TheScreen->BarVBorder+TheScreen->WBorTop;
  118.  
  119.     numcolours=1 << (TheScreen->RastPort.BitMap->Depth);
  120.     if (numcolours>MAX_COLOURS) numcolours=MAX_COLOURS;
  121.  
  122.     if (numcolours<3)
  123.     {    /* Some silly person is running with 2 colours... */
  124.         ri->BackPen=0;
  125.         ri->Highlight=1;
  126.         ri->Shadow=1;
  127.         ri->TextPen=1;
  128.     }
  129.     else
  130.     {
  131.         for (loop=0;loop<numcolours;loop++)
  132.         {
  133.             colours[loop]=GetRGB4(TheScreen->ViewPort.ColorMap,(LONG)loop);
  134.             colourlevels[loop]=ColourLevel(colours[loop]);
  135.             pens[loop]=loop;
  136.         }
  137.  
  138.         /* Sort darkest to brightest... */
  139.         for (loop=0;loop<(numcolours-1);loop++)
  140.         {
  141.             for (loop1=loop+1;loop1<numcolours;loop1++)
  142.             {
  143.                 if (colourlevels[loop]>colourlevels[loop1])
  144.                 {
  145.                     tmp=colourlevels[loop];
  146.                     colourlevels[loop]=colourlevels[loop1];
  147.                     colourlevels[loop1]=tmp;
  148.  
  149.                     tmp=colours[loop];
  150.                     colours[loop]=colours[loop1];
  151.                     colours[loop1]=tmp;
  152.  
  153.                     tmp=pens[loop];
  154.                     pens[loop]=pens[loop1];
  155.                     pens[loop1]=tmp;
  156.                 }
  157.             }
  158.         }
  159.  
  160.         /* Now, pick the pens... HightLight... */
  161.         loop=numcolours-1;
  162.         while (!(ri->Highlight=pens[loop--]));
  163.  
  164.         /* and Shadow... */
  165.         loop=0;
  166.         while (!(ri->Shadow=pens[loop++]));
  167.  
  168.         /* The BackGround pen... */
  169.         if (!pens[loop]) loop++;
  170.         ri->BackPen=pens[backpen=loop];
  171.  
  172.         loop1=0;
  173.         for (loop=0;loop<numcolours;loop++)
  174.         {
  175.             tmp=ColourDifference(colours[loop],colours[backpen]);
  176.             if (tmp>loop1)
  177.             {
  178.                 loop1=tmp;
  179.                 ri->TextPen=pens[loop];
  180.             }
  181.         }
  182.     }
  183. }
  184.  
  185. VOID CleanUp_RenderInfo(struct RenderInfo *ri)
  186. {
  187.     if (ri) FreeMem(ri,sizeof(struct RenderInfo));
  188. }
  189.  
  190. /*
  191.  * Use this screen for the render information.  If the screen is NULL
  192.  * it will use the WorkBench screen...
  193.  */
  194. struct RenderInfo *Get_RenderInfo(struct Screen *TheScreen)
  195. {
  196. register    struct    RenderInfo    *ri;
  197.  
  198.     if (ri=AllocMem(sizeof(struct RenderInfo),MEMF_PUBLIC|MEMF_CLEAR))
  199.     {
  200.         NewFillIn_RenderInfo(ri,TheScreen);
  201.     }
  202.     return (ri);
  203. }
  204.